import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

import static java.lang.Math.abs;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-07-16
 * Time: 17:07
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int key = scan.nextInt();
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(1);
        for (int i = 2; ; i++) {
            int min = list.get(i-2);
            int max = list.get(i-1);
            if( key >= min && key<=max) {
                int m = key - min;
                int n = max -key;
                if( m>n) {
                    System.out.println(n);
                } else {
                    System.out.println(m);
                }
                break;
            }
            list.add(min + max);

        }
    }
}
